let box = document.querySelector('.list > .content > ul')
let bac = document.querySelector('.list')
let boxli
const xhr = new XMLHttpRequest()
xhr.open('GET', '/djh?callback=getSphCommList1632395734568&_=1632395734571')
xhr.onload = function () {
    let res = xhr.responseText.replace('getSphCommList1632395734568(', '')
    res = res.substr(0, res.length - 2)
    console.log(JSON.parse(res))
    let a = JSON.parse(res).data.commInfoList
    
    for (let i = 0; i < a.length; i++) {
        box.innerHTML += `
        <li>
        <img src="${ a[i].newCommImgUrl }" alt="">
        <p>${ a[i].grppurName }</p>
        <p>${ a[i].gbCommHot }</p>
        <div>
        <p><span>￥${ a[i].gbPrice }</span><span>${ a[i].payPrice }</span><span>爆卖中</span></p>
        <p>立即抢购</p>
        </div>
        </li>
        `
    }
    boxli = document.querySelectorAll('.list > .content > ul > li')
    bac.style.height = Math.ceil(a.length / 4) * 420 + 'px'
    boxli.forEach(item => {
        item.onclick = function () {
            window.location.href = './detail.html'
        }
    })
}
xhr.send()


let index = document.querySelector('.header > .content > .header_left > li:nth-child(1)')
let login = document.querySelector('.header > .content > .header_right > li:nth-child(1)')
let register = document.querySelector('.header > .content > .header_right > li:nth-child(2)')


index.onclick = function () {
    window.location.href = './index.html'
}

login.onclick = function () {
    window.location.href = './login.html'
}

register.onclick = function () {
    window.location.href = './register.html'
}
